package com.qc31.baselib.rx

import android.view.View
import android.widget.TextView
import com.jakewharton.rxbinding4.view.clicks
import com.jakewharton.rxbinding4.widget.textChanges
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Observable
import java.util.concurrent.TimeUnit

fun View.queryThrottle(): Observable<Unit> {
    return clicks().throttleFirst(500, TimeUnit.MILLISECONDS)
}

fun View.clickThrottle(): Observable<Unit> {
    return clicks().throttleFirst(200, TimeUnit.MILLISECONDS)
}

fun TextView.textChangesNoLong(): Observable<String> {
    return textChanges().observeOn(AndroidSchedulers.mainThread()).map(CharSequence::toString)
}
